home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2003 November / PCWK1103B.iso / DesignCAD 3D Max PLUS trial 30 / DATA1.CAB / Example_Files / Sample_Macros / 600_2_Area.d3m < prev    next >
Encoding:
Text File  |  2003-09-29  |  6.6 KB  |  310 lines

  1. ' This is the second macro in the 600 series, which creates the
  2. ' small area boxes.  Once done, if the area is larger than 46 meters
  3. ' is launches the large area macro.  If not, it launches the small area
  4. ' macro, see the bottom of the file for the chain command.
  5. '
  6. ' Get Values from data file.
  7. '
  8. ' Based on RType chosen by user above
  9.     open "i", 1, "*\sample macros\600.txt"
  10. ' Assign #s found to Variables
  11.     Input #1, AddLen
  12.     Input #1, TH
  13.     Input #1, PanNum2
  14.     Input #1, PanNum
  15. ' Close File
  16.     Close #1
  17. '
  18.     '
  19.             ' Get Current Layer
  20.                 CurLay = Sys(3)
  21.                 '
  22.             ' Get Current Line Width
  23.                 CurThick = Sys(6)
  24.                 '
  25.             ' Set Rubber band type to Plane for area command
  26.                 Sys(41) = 13
  27.                 '
  28.             ' Make Layer 11 the current layer
  29.                 Layer(11) = 14
  30.                 Sys$(93) = "Please Leave Empty !!"
  31.                 Precision 2
  32.                 '
  33.             ' Prompt User for up to 50 points for boundary of area
  34.                 setpoint "Set up to 50 points for the area . . . then press Enter when finished." 50
  35.                 '
  36.             ' If user set only 2 points, there can be no area
  37.                   if sys(1) < 3 then
  38.                 Message "Please run the program again and set more than 2 points for the area."
  39.                 End
  40.                      endif
  41.             '
  42.             ' Create an Array for the points the user sets
  43.                 Dim X(50), Y(50), Z(50)
  44.                 '
  45.             ' Store points the user just set into the Array
  46.                 for a = 1 to Sys(1)
  47.                     PointVal X(a), Y(a), Z(a) a
  48.                 next a
  49.                 '
  50.             ' Loop to Draw Plane with points from the Array
  51.                 >Plane
  52.                 {
  53.                 for a = 1 to Sys(1)
  54.                     <Pointxyz [X(a), Y(a), Z(a)]
  55.                 next a
  56.                 }
  57.                 '
  58.             ' Select Layer 11
  59.                 >SelectLayer
  60.                 {
  61.                 <Layer 11
  62.                 }
  63.                 '
  64.             ' Get XYZ location of the cursor after Plane is done
  65.                 getxy x1 y1 z1
  66.             '
  67.             ' Set Count to the number of entities in the drawing
  68.             ' The plane was drawn last, so it's the item we want
  69.                 Count = Sys(9)
  70.                 '
  71.             ' Get Entity ID for the plane just drawn
  72.                 getselect 1, entID
  73.                 '
  74.             ' Get Area (or Square Meters) of the plane
  75.                 Area1 = Area(entID)
  76.                 '
  77.             ' Get Length (or Parameter) of the plane
  78.                 Len0 = Length(entID)
  79.                 '
  80.                 Len1 = Len0 + AddLen
  81.                 '
  82.             ' Round Results up to nearest whole #
  83.                 Precision 0
  84.                 Area2 = ROUND(Area1)
  85.                 Len2 = ROUND(Len1)
  86.                 Precision 2
  87.                 '
  88.             ' Section Added to account for Areas of 46 or less
  89.                 if Area1 <= 46 then
  90.                     Box = 0
  91.                 else
  92.                     Box = 1
  93.                 endif
  94.             ' Delete Plane, it's no longer needed
  95.                 >SelectDelete
  96.                 {
  97.                 }
  98.                 '
  99.             ' Display Results to screen for testing
  100.                 ' Message Area2
  101.                 ' Message Len2
  102.             ' Silent Mode On
  103.                 Sys(36) = 1
  104.             ' Add Area to Layer 12
  105.                 Layer(12) = 14
  106.                 Sys$(93) = "6x6 Areas"
  107.                 >Attribute
  108.                 {
  109.                 <size 2
  110.                 <text [Area1]
  111.                 <pointxyz 10, 10, 0
  112.                 }
  113.             ' Add Length to Layer 13
  114.                 Layer(13) = 14
  115.                 Sys$(93) = "6x6 Lengths"
  116.                 >Attribute
  117.                 {
  118.                 <size 2
  119.                 <text [Len1]
  120.                 <pointxyz 10, 10, 0
  121.                 }
  122.             ' Back to Layer 11
  123.                 Layer(11) = 14
  124.                 '
  125.             ' Select Object when Created
  126.                 Sys(242) = 1
  127.                 '
  128.             ' Silent Mode On
  129.                 Sys(36) = 1
  130. ' Rem this back in if text sizes under 1 become a problem
  131.     ' if TH < 1 then TH = 1
  132. ' Get Old Text Height
  133.     OLDTH = Sys(12)
  134. ' Set new Text height
  135.     Sys(12) = TH
  136.             ' Create the Area Info Box    
  137.             ' Convert to Strings for use in Text Block
  138.                 Precision 0
  139.                 Area$ = Area2
  140.                 Len$ = Len2
  141.             ' Strings for Text Labels
  142.                 Area2$ = "Sm"
  143.                 Len2$ = "Lm"
  144.                 Precision 2
  145.             ' Select Object when Created is on
  146.                 Sys(242) = 1
  147.             '
  148.             ' Get Current Drawing Color    
  149.                 ccRed = Sys(300)
  150.                 ccGreen = Sys(301)
  151.                 ccBlue = Sys(302)
  152.             ' Create New File to draw Area box in
  153.                 >New
  154.                 {
  155.                 }
  156.             ' Set Color to Red
  157.                 Sys(300) = 255
  158.                 Sys(301) = 0
  159.                 Sys(302) = 0
  160.             ' Back to Layer 11
  161.                 Layer(11) = 14
  162.                 '
  163.             ' Not sure if this is still needed . . . 
  164.                 MinnY = Sys(187)
  165. ' Set Current Line Width to Zero
  166.     Sys(6) = 0
  167.             ' Make Text Block of information
  168.                 >TextBlock
  169.                 {
  170.                 <size [TH]
  171.                 <Distance 0.5
  172.                 <TextBegin
  173.                 <Text [Area$]
  174.                 <Text  [Len$]
  175.                 <justification 2
  176.                 <pointxyz 0, [MinnY - 20], 0
  177.                 }
  178.             ' Get Current Max X values to place labled behind the text values
  179.                 M = Sys(198)
  180.                 M = M + 1
  181.             ' Reset Color
  182.                 Sys(300) = ccRed
  183.                 Sys(301) = ccGreen
  184.                 Sys(302) = ccBlue
  185.                 '
  186.             ' Select Object when Created is off
  187.                 Sys(242) = 0
  188.             ' Make Text Block of information
  189.                 >TextBlock
  190.                 {
  191.                 <Style 0
  192.                 <Distance 0.5
  193.                 <TextBegin
  194.                 <Text [Area2$]
  195.                 <Text [Len2$]
  196.                 <justification 0
  197.                 <pointxyz [M], [MinnY - 20], 0
  198.                 }
  199.             '
  200.             ' Select Object when Created is off
  201.                 Sys(242) = 0
  202.             '
  203.             ' Select Entire Drawing
  204.                 >SelectAll
  205.                 {
  206.                 }
  207.                 '
  208.             ' Scale down the Info Box to a much smaller size
  209.                 ' Based on Diff in line 5
  210.                 ' Move Info Box to resize it 
  211.                 '    >Move
  212.                 '    {
  213.                 '    <Type 0
  214.                 '    <Pointxyz 0, 0, 0
  215.                 '    <Pointrel [Diff], 0, 0
  216.                 '    }
  217.                 '    '
  218.             ' Copy Area Box back into main drawing
  219.                 >Copy
  220.                 {
  221.                 }
  222.             '
  223.             ' Close Temp Drawing
  224.                 >Close
  225.                 {
  226.                 <SaveChanges 0
  227.                 }
  228.             ' Silent Mode Off
  229.                 Sys(36) = 0
  230.             ' Refresh the Screen
  231.                 >Regenerate
  232.                 {
  233.                 }
  234.             ' Back to Layer 11
  235.                 Layer(11) = 14
  236.                 '
  237.             ' Paste the info box in again
  238.                 >Paste
  239.                 {
  240.                 <Type 0
  241.                 ' 0 = Changeable scale (based on distance between handles 1 and 2); 1 = Fixed scale (always paste at original size)
  242.                 <SelectOnly 0
  243.                 ' 
  244.                 ' 0 = select the pasted object; 1 = leave the pasted object unselected
  245.                 <pointxyz 0,0,0
  246.                 }
  247.                 '
  248.             ' Select Layer 11
  249.                 >SelectLayer
  250.                 {    
  251.                 <Layer 11
  252.                 }
  253.             ' Get Min and Max of the current Selection
  254.                 MinX = Sys(196) 
  255.                 MinY = Sys(197) 
  256.                 MaxX = Sys(198) 
  257.                 MaxY = Sys(199) 
  258.             ' Set Handle
  259.                 >SetHandle
  260.                 {
  261.                 <pointxyz [MinX,MinY],0
  262.                 <pointxyz [MaxX,MinY],0
  263.                 }
  264.             ' Loop for Moving Box from Layer 11 to the current layer
  265.                 for a = 1 to Sys(9)
  266.                     getattr a, type, select, laynum, group, red, green, blue
  267.                     
  268.                     if laynum = 11 then laynum = 9
  269.                         Putattr a, type, select, laynum, group, red, green, blue
  270.                     next a
  271.             ' Switch to and Name Layer 9
  272.                 Sys(3) = 9
  273.                 Sys$(93) = "6x6 Area Boxes"
  274.                 '    
  275.             ' Silent Mode Off
  276.                 Sys(36) = 0
  277.                 '
  278.             ' Refresh the Drawing
  279.                 >Regenerate
  280.                 {
  281.                 }
  282.             ' Move the Box
  283.                 >Move
  284.                 {
  285.                 <Type 0
  286.                 }
  287.                 '
  288.             ' Refresh the Screen to see text in area box
  289.                 >Regenerate
  290.                 {
  291.                 }
  292.                 '
  293.             ' Deselect the Box after it's been placed
  294.                 >PointSelect
  295.                 {
  296.                 <Type 0
  297.                 <pointxyz -100, -100, 100
  298.                 }
  299.                 '
  300.             ' Return to previous Current Layer
  301.                 Sys(3) = CurLay
  302.                 '
  303. if Area1 <= 46 then
  304.     Chain "600_3_InfoS.d3m"
  305. else
  306.     Chain "600_3_InfoL.d3m"
  307. endif
  308. end
  309.  
  310.